package com.hckj.managersystemdemo.config;

import com.hckj.managersystemdemo.intercept.LoginHandlerIntercept;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * WebMvc 配置
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        //转发 , 视图控制器
        registry.addViewController("/").setViewName("login.html");
//        registry.addViewController("/main.html").setViewName("/list.do");
        //重定向
//        registry.addRedirectViewController("/main.html","list.do");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //添加拦截器，指定路径 + 排除路径
        registry.addInterceptor(new LoginHandlerIntercept())
                .addPathPatterns("/**").
                excludePathPatterns(
                        "/","/eitilogin.html","/user/login","/css/**","js/**","img/**");
    }
}
